package cn.webestar.scms.user.api.dto.Message;

import cn.webestar.scms.commons.api.LimitBody;
import cn.webestar.scms.user.entity.Message;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Date;

@Data
@Schema(description = "MessageLimitDTO")
public class MessageLimitDTO extends LimitBody {

    @Schema(description = "租户")
    private Long cid;

    @Schema(description = "消息类型 1：系统消息")
    private Integer type;

    @Schema(description = "标题")
    private String title;

    @Schema(description = "内容")
    private String content;

    @Schema(description = "长引用类型")
    private Integer refType;

    @Schema(description = "长引用id")
    private Long refId;

    @Schema(description = "创建时间")
    private Date createTime;

    @Override
    public LambdaQueryWrapper<Message> toQueryWapper() {
        LambdaQueryWrapper<Message> queryWrapper = new LambdaQueryWrapper<>();
        if (cid!=null) {
            queryWrapper.eq(Message::getCid, cid);
        }
        if (type!=null) {
            queryWrapper.eq(Message::getType, type);
        }
        if (StringUtils.hasText(title)) {
            queryWrapper.eq(Message::getTitle, title);
        }
        if (StringUtils.hasText(content)) {
            queryWrapper.eq(Message::getContent, content);
        }
        if (refType!=null) {
            queryWrapper.eq(Message::getRefType, refType);
        }
        if (refId!=null) {
            queryWrapper.eq(Message::getRefId, refId);
        }
        if (createTime!=null) {
            queryWrapper.eq(Message::getCreateTime, createTime);
        }
        queryWrapper.last("LIMIT " + this.getOffset() + "," + this.getLimit());
        return queryWrapper;
    }
    
}
